﻿@{
    ViewData["Title"] = "添加路径细节详情配置";
    Layout = "_Edit";
}
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-add">
        <input type="hidden" class="input-text" value="@Model.ID" id="id" name="id">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>路径：</label>
            <div class="formControls col-xs-3 col-sm-2">
                <span class="select-box">
                    <select class="select" size="1" name="RouteID" id="RouteID" onchange="OnRouteChange()">
                        <option value="">--请选择--</option>
                        @foreach (var item in Model.RouteInfos)
                        {
                            if (Model.RouteID + "" == item.ID)
                            {
                                <option value="@item.ID" selected>@item.RouteInfo</option>
                            }
                            else
                            {
                                <option value="@item.ID">@item.RouteInfo</option>
                            }
                        }
                    </select>
                </span>
            </div>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="" placeholder="" id="FromStation" name="FromStation">
            </div>
            <div class="formControls col-xs-1 col-sm-1">
                ->
            </div>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="" placeholder="" id="ToStation" name="ToStation">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前段调度类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="DispatchType" id="DispatchType">
                        <option value="-1">--请选择--</option>
                        @foreach (var item in Model.DispatchTypes)
                        {
                            if (Model.DispatchTypeId == item.ID)
                            {
                                <option value="@item.ID" selected>@item.Desception</option>
                            }
                            else
                            {
                                <option value="@item.ID">@item.Desception</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前段起始设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.FromEquipment" placeholder="" id="FromEquipment" name="FromEquipment">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前段起始货位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.FromCargo" placeholder="" id="FromCargo" name="FromCargo">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前段起始货位列：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.FromCargoColumn" placeholder="" id="FromCargoColumn" name="FromCargoColumn">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前段目标设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ToEquipment" placeholder="" id="ToEquipment" name="ToEquipment">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前段目标货位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ToCargo" placeholder="" id="ToCargo" name="ToCargo">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否只有前段：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    @if (Model.IsStart)
                    {
                        <input name="IsStart" type="radio" id="IsStart-true" value="1" checked>
                    }
                    else
                    {
                        <input name="IsStart" type="radio" id="IsStart-true" value="1">

                    }
                    <label for="IsStart-true">是</label>
                </div>
                <div class="radio-box">
                    @if (Model.IsStart)
                    {
                        <input name="IsStart" type="radio" id="IsStart-false" value="0">
                    }
                    else
                    {
                        <input name="IsStart" type="radio" id="IsStart-false" value="0" checked>
                    }
                    <label for="IsStart-false">否</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>后段调度类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="DispatchType2" id="DispatchType2">
                        <option value="-1">--请选择--</option>
                        @foreach (var item in Model.DispatchTypes)
                        {
                            if (Model.DispatchTypeId == item.ID)
                            {
                                <option value="@item.ID" selected>@item.Desception</option>
                            }
                            else
                            {
                                <option value="@item.ID">@item.Desception</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>后段起始设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="FromEquipment2" name="FromEquipment2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>后段起始货位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="FromCargo2" name="FromCargo2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>后段起始货位列：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="FromCargoColumn2" name="FromCargoColumn2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>后段目标设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="ToEquipment2" name="ToEquipment2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>后段目标货位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="ToCargo2" name="ToCargo2">
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="button" onclick="operate()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

@section javascript{

    <script>
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $(function () {
            //var js_routeid = @Model.Js_RouteID;
            //console.log(js_routeid);
            var routeID = $("#RouteID").val();
            console.log(routeID);
            if (routeID != 0) {
                loadPrevsions(routeID);
            }
        });

        function loadPrevsions(routeID) {
            console.log(routeID);
            $("#PrevionsID").empty();
            $.ajax({
                method: "POST",
                async: false,
                url: "/routedetailinfo/getroutedetailinfobyrouteid",
                contentType: "application/x-www-form-urlencoded",
                dataType: "json",
                data: {
                    routeID: routeID
                },
                success: function (data) {
                    console.log(data);
                    var top = "<option value=\"0\">--请选择--</option>";
                    $("#PrevionsID").append(top);
                    $.each(data, function (index, item) {
                        var op = "<option value=\"" + item.js_ID + "\">" + item.target + "</option>"
                        //if(@Model.Js_PrevionsID == item.js_ID + ""){
                        if (item.js_ID.indexOf("@Model.Js_PrevionsID") > -1) {
                            op = "<option value=\"" + item.js_ID + "\" selected>" + item.target + "</option>"
                        }
                        $("#PrevionsID").append(op);
                    })
                }

            });
        }

        function OnRouteChange() {
            var routeID = $("#RouteID").val();
            console.log(routeID);
            loadPrevsions(routeID);
        }
        function operate() {
            var RouteID = $("#RouteID").val();
            if (RouteID == null || RouteID == "") {
                popupAlert('请选择路径', 2, function (data) { layer.close(data); });
                return;
            }
            //var PrevionsID=$("#PrevionsID").val();
            //if(PrevionsID==null||PrevionsID=="")
            //{
            //   popupAlert('请选择上一货位',2,function(data){layer.close(data);});
            //  return;
            //}

            var FromStation = $("#FromStation").val();
            if (FromStation == null || FromStation == "") {
                popupAlert('起始工位不能为空', 2, function (data) { layer.close(data); });
                return;
            }
            var ToStation = $("#ToStation").val();
            if (ToStation == null || ToStation == "") {
                popupAlert('目标工位不能为空', 2, function (data) { layer.close(data); });
                return;
            }
            var isStart = $("#IsStart").val();
            console.log(isStart);
            var DispatchType = $("#DispatchType").val();
            if (DispatchType == null || DispatchType == "" || DispatchType == -1) {
                popupAlert('请选择调度类型', 2, function (data) { layer.close(data); });
                return;
            }
            var FromEquipment = $("#FromEquipment").val();
            if (FromEquipment == null || FromEquipment == "") {
                popupAlert('起始设备不能为空', 2, function (data) { layer.close(data); });
                return;
            }
            var FromCargo = $("#FromCargo").val();
            if (FromCargo == null || FromCargo == "") {
                popupAlert('起始货位不能位空', 2, function (data) { layer.close(data); });
                return;
            }
            var FromCargoColumn = $("#FromCargoColumn").val();
            if (FromCargoColumn == null || FromCargoColumn == "") {
                popupAlert('起始货位列不能为空', 2, function (data) { layer.close(data); });
                return;
            }
            var ToEquipment = $("#ToEquipment").val();
            if (ToEquipment == null || ToEquipment == "") {
                popupAlert('目标设备不能为空', 2, function (data) { layer.close(data); });
                return;
            }
            var ToCargo = $("#ToCargo").val();
            if (ToCargo == null || ToCargo == "") {
                popupAlert('目标货位不能为空', 2, function (data) { layer.close(data); });
                return;
            }
            SubmitFormForAjax("/routedetailinfo/AddMultiRouteDetailInfo", $("#form-add").serialize(), function (data) {
                if (data.result) {
                    popupAlert('提交成功', 1, function () { closePageLayer(true); });
                } else {
                    popupAlert(data.message, 2, function (data) { layer.close(data); });
                }
            }, true);
        }
    </script>
}